Skip to content

Update behavior for postCommand.strategy=post-index-change #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2025

Conversation

derrickstolee
Copy link

This feature was introduced in #736 but had a few pain points that were discovered when testing the full replacement of the existing post-index-change and post-command hooks in our internal environment:

  1. When using core.hooksPath to point to a directory within the worktree, the sentinel files were being written into the worktree. Write to $GITDIR/info/ instead.
  2. The existing internal post-index-change hook only signaled that work needed to be done if actually the worktree changed. Make the sentinel file logic more restrictive to only write in these cases.

Tests are added to confirm both of these behavior changes.

This change to use the 'info/' directory instead of the 'hooks/'
directory is important because the hooks dir could be redirected to the
source tree.

Modify the test in such a way that this code change would fail due to
being unable to write to the internal hooks directory.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Before making the post-index-change logic more advanced for the
postCommand.strategy=post-index-change feature, extract the code into a
new method that will be easier to update in the future.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
The postCommand.strategy=post-index-change config was designed to
replace some internal hook usage. This internal hook was more
restrictive than the initial feature was designed. Specifically, it
ignored index updates that did not update the worktree. With the
existing implementation, this causes more work done in the post-command
hook than intended.

Update the code to write a sentinel file only when the worktree is
changed.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
@derrickstolee derrickstolee requested review from dscho and mjcheetham May 7, 2025 14:15
@derrickstolee derrickstolee self-assigned this May 7, 2025
dscho
dscho previously approved these changes May 7, 2025
Copy link
Member

@dscho dscho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, and since the feature is young enough, I have no objection to that minor behavior change.

The previously-named 'post-index-change' value for
'postCommand.strategy' did the following two things:

 1. Avoid running the post-command hook unless the post-index-change
    hook _would_ run with a signal that the worktree changed.

 2. Avoid running any installed post-index-change hooks.

The additional restriction of the worktree change in (1) makes this name
less appropriate. Also, item (2) seems to be a side-effect that we
should avoid. We would like to allow both behaviors to exist.

Update the value and behavior, including the tests.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
dscho
dscho previously approved these changes May 7, 2025
Now that we don't skip the post-index-change hook, we don't need to pass
the return value as an out-parameter in this method.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
@dscho dscho enabled auto-merge May 7, 2025 17:48
@dscho dscho merged commit 107f41a into microsoft:vfs-2.49.0 May 7, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants